SUBROUTINE check_param
USE param
USE global
IMPLICIT NONE
INTEGER :: i,j,k
INTEGER :: n_line,n_atom2

! i=1
i=1
OPEN(UNIT=1,FILE=lammps_file(i)%source,STATUS='OLD')
! ITEM: TIMESTEP
READ(1,'(A)') eatline
READ(1,*) lammps_file(i)%time_step
! ITEM: NUMBER OF ATOMS
READ(1,'(A)') eatline
READ(1,*) lammps_file(i)%n_atom
CLOSE(1)
n_atom=lammps_file(i)%n_atom
! i>1
DO i=2,n_lammps_file
   OPEN(UNIT=1,FILE=lammps_file(i)%source,STATUS='OLD')
   ! ITEM: TIMESTEP
   READ(1,'(A)') eatline
   READ(1,*) lammps_file(i)%time_step
   ! ITEM: NUMBER OF ATOMS
   READ(1,'(A)') eatline
   READ(1,*) lammps_file(i)%n_atom
   CLOSE(1)
   IF(n_atom.NE.lammps_file(i)%n_atom) STOP 'ERR:n_atom for each lammps file must be equal.'
END DO

! Determine nside
IF(ltype.EQ.1) THEN
   ! BCC
   nside_real=(REAL(n_atom)*0.5)**(1.0/3.0)
   nside_int=INT(nside_real)
ELSE IF(ltype.EQ.2) THEN
   ! FCC
   nside_real=(REAL(n_atom)*0.25)**(1.0/3.0)
   nside_int=INT(nside_real)
ELSE
   STOP 'ERR:Unallowable lattice structure.(1:BCC,2:FCC)'
END IF

! cell box
n_cell=nside_int**3
box_width=dist_a0_ang*nside_real

!ALLOCATE(cell_box_map(0:nside_int-1,0:nside_int-1,0:nside_int-1))
ALLOCATE(cell_box_map(-1:nside_int,-1:nside_int,-1:nside_int))
ALLOCATE(cell_box(0:n_cell-1))

! Write to log file and screen (n_atom,n_cell,nside_int)
1000 FORMAT(3X,'Number of atoms and lattice: ',I7)
1001 FORMAT(3X,'Number of cell: ',I7,'=',I4,' * ',I4,' * ',I4)
OPEN(UNIT=1,FILE=lgfn,STATUS='OLD',ACCESS='APPEND')
WRITE(1,1000) n_atom
PRINT 1000,n_atom
WRITE(1,1001) n_cell,nside_int,nside_int,nside_int
PRINT 1001,n_cell,nside_int,nside_int,nside_int
CLOSE(1)

! Xmakemol
corner(1)=0.0
corner(2)=nside_real*dist_a0_ang
n_xml_corner=0
DO i=1,2
   DO j=1,2
      DO k=1,2
         n_xml_corner=n_xml_corner+1
         xml_corner(n_xml_corner)%px=corner(i)
         xml_corner(n_xml_corner)%py=corner(j)
         xml_corner(n_xml_corner)%pz=corner(k)
      END DO
   END DO
END DO

! A to nm
aton=0.1

END SUBROUTINE check_param
